package com.meila.cms.controller;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.OutputStream;

import javax.inject.Inject;
import javax.servlet.ServletContext;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.context.ContextLoader;
import org.springframework.web.context.WebApplicationContext;

import com.meila.cms.auth.AuthClass;
import com.meila.cms.services.IFileService;
import com.meila.cms.util.config.Property;

@Controller
@RequestMapping("/before")
@AuthClass("login")
public class FileController extends BaseController{

	private IFileService  fileService;
	
 
	public IFileService getFileService() {
		return fileService;
	}
	@Inject
	public void setFileService(IFileService fileService) {
		this.fileService = fileService;
	}


	/**
	 * 由于kindeditor文件保存在其他文件夹下所以以流的形式重新进行访问
	 * @param dirname
	 * @param username
	 * @param type
	 * @param year
	 * @param month
	 * @param picname
	 * @param extname
	 */
	@RequestMapping(value="/getFile/{dirname}/{username}/{type}/{year}/{month}/{picname}")
	public void getFile(@PathVariable String dirname,
			@PathVariable String username,@PathVariable String type,
			@PathVariable String year,@PathVariable String month,
			@PathVariable String picname){
		    
		String extname= picname.substring(picname.length()-3);
		picname= picname.substring(0,picname.length()-3);
		fileService.getFile(dirname,username,type,year,month,picname,extname,request,response);
		
	}
	
	@RequestMapping("/kindeditorContent")
	public String kindeditorContent(int designid,Model model) {
		
		fileService.kindeditorContent(designid,model);
		
		return "carDesign/kindeditorContent";
	}
}
